package com.easyardemo;

import android.app.Application;
import android.content.ServiceConnection;

import com.easyardemo.app.HttpApi;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;

/**
 * @author dell for jin
 */
public class ArApplication extends Application {

    private static ArApplication mInstance;

    @Override
    public void onCreate() {
        super.onCreate();
        disableAPIDialog();
        HttpApi.CONTENT_URL = HttpApi.HOST + ":" + HttpApi.PORT + "/content";
        mInstance = this;
    }

    /**
     * android 9.0 调用私有api弹框的解决方案
     */
    private void disableAPIDialog() {
        try {
            Class aClass = Class.forName("android.content.pm.PackageParser$Package");
            Constructor declaredConstructor = aClass.getDeclaredConstructor(String.class);
            declaredConstructor.setAccessible(true);
        } catch (Exception e) {
            e.printStackTrace();
        }
        try {
            Class cls = Class.forName("android.app.ActivityThread");
            Method declaredMethod = cls.getDeclaredMethod("currentActivityThread");
            declaredMethod.setAccessible(true);
            Object activityThread = declaredMethod.invoke(null);
            Field mHiddenApiWarningShown = cls.getDeclaredField("mHiddenApiWarningShown");
            mHiddenApiWarningShown.setAccessible(true);
            mHiddenApiWarningShown.setBoolean(activityThread, true);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


    public static synchronized ArApplication getInstance() {
        return mInstance;
    }

}
